package com.algorithm.lesson_04;

import java.util.Iterator;
import java.util.LinkedList;

public class Queue<T> {
	private LinkedList<T> queue;

	public Queue() {
		queue = new LinkedList<>();
	}

	/**
	 * 判断队列是否为空
	 * 
	 * @return
	 */
	public boolean isEmpty() {
		return queue.isEmpty();
	}

	/**
	 * 队列的大小
	 * 
	 * @return
	 */
	public int size() {
		return queue.size();
	}

	/**
	 * 进队
	 * 
	 * @param value
	 */
	public void add(T value) {
		queue.addLast(value);
	}

	/**
	 * 出队
	 * 
	 * @return
	 */
	public T poll() {
		return queue.pollFirst();
	}

	/**
	 * 查看队头
	 * 
	 * @return
	 */
	public T peek() {
		return queue.peekFirst();
	}

	@Override
	public String toString() {
		String descQueue = "[";

		Iterator<T> it = queue.iterator();

		while (it.hasNext()) {
			descQueue += it.next().toString() + ",";
		}

		descQueue = descQueue.substring(0, descQueue.length() - 1) + "]";

		return descQueue;
	}
}
